<template>
  <slide-view
    v-empty="!canShowDetail"
    :listener-ids="listenerIDs"
    :no-listener-ids="noListenerIDs"
    :no-listener-class="noListenerClass"
    :body-style="{padding: 0, height: '100%'}"
    xs-empty-icon="nopermission"
    xs-empty-text="暂无权限"
  >
    <div class="close-button" @click="hideView">
      <i class="el-icon-close"></i>
    </div>
    <flexbox
      v-loading="loading"
      v-if="canShowDetail"
      direction="column"
      align="stretch"
      class="d-container">
      <finance-detail-head
        :detail="detailData"
        :head-details="headDetails"
        :id="id"
        crm-type="supplier"
        @handle="detailHeadHandle"
        @close="hideView"/>
      <div class="tabs">
        <el-tabs
          v-model="tabCurrentName"
          @tab-click="handleClick">
          <el-tab-pane
            v-for="(item, index) in tabnames"
            :key="index"
            :label="item.label"
            :name="item.name"/>
        </el-tabs>
      </div>
      <div class="t-loading-content">
        <keep-alive>
          <component
            :is="tabName"
            :detail="detailData"
            :id="id"
            crm-type="supplier"/>
        </keep-alive>
      </div>
    </flexbox>
    <finance-create-view
      v-if="isCreate"
      :action="{type: 'update', id: id, batchId: detailData.batchId, supplierId: detailData.supplierId}"
      finance-type="supplier"
      @save-success="editSaveSuccess"
      @hiden-view="isCreate=false"/>
  </slide-view>
</template>

<script>
import { financeSupplierRead } from '@/api/financemanagement/supplier'
import SlideView from '@/components/SlideView'
import FinanceDetailHead from '../components/FinanceDetailHead'
import FinanceBaseInfo from '../components/FinanceBaseInfo' // 产品基本信息
import RelativeFiles from '../components/RelativeFiles' // 相关附件
import RelativeHandle from '../components/RelativeHandle' // 相关操作

import FinanceCreateView from '../components/FinanceCreateView' // 新建页面
import detail from '../mixins/detail'

export default {
  /** 客户管理 的 客户详情 */
  name: 'ProductDetail',
  components: {
    SlideView,
    FinanceDetailHead,
    FinanceBaseInfo,
    RelativeFiles,
    RelativeHandle,
    FinanceCreateView
  },
  mixins: [detail],
  props: {
    // 详情信息id
    id: [String, Number],
    // 监听的dom 进行隐藏详情
    listenerIDs: {
      type: Array,
      default: () => {
        return ['crm-main-container']
      }
    },
    // 不监听
    noListenerIDs: {
      type: Array,
      default: () => {
        return []
      }
    },
    noListenerClass: {
      type: Array,
      default: () => {
        return ['el-table__body']
      }
    }
  },
  data() {
    return {
      loading: false, // 展示加载loading
      crmType: 'supplier',
      detailData: {}, // read 详情
      headDetails: [
        { title: '供应商简称', value: '' },
        { title: '联系人', value: '' },
        { title: '负责人', value: '' },
        { title: '年产值', value: '' }
      ],
      tabnames: [
        { label: '基本信息', name: 'basicinfo' },
        { label: '附件', name: 'file' },
        { label: '操作记录', name: 'operationlog' }
      ],
      tabCurrentName: 'basicinfo',
      isCreate: false // 编辑操作
    }
  },
  computed: {
    tabName() {
      if (this.tabCurrentName == 'basicinfo') {
        return 'finance-base-info'
      } else if (this.tabCurrentName == 'file') {
        return 'relative-files'
      } else if (this.tabCurrentName == 'operationlog') {
        return 'relative-handle'
      }
      return ''
    }
  },
  mounted() {},
  methods: {
    getDetial() {
      this.loading = true
      financeSupplierRead({
        supplierId: this.id
      })
        .then(res => {
          this.loading = false
          this.detailData = res.data

          this.headDetails[0].value = res.data.供应商简称
          this.headDetails[1].value = res.data.单位
          this.headDetails[2].value = res.data.负责人
          this.headDetails[3].value = res.data.年产值
        })
        .catch(() => {
          this.loading = false
        })
    },
    //* * 点击关闭按钮隐藏视图 */
    hideView() {
      this.$emit('hide-view')
    },
    //* * tab标签点击 */
    handleClick(tab, event) {},
    editSaveSuccess() {
      this.$emit('handle', { type: 'save-success' })
      this.getDetial()
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '../../financemanagement/styles/crmdetail.scss';
</style>
